package cc.mrbird.assets.controller;

import cc.mrbird.assets.domain.EquipmentModel;
import cc.mrbird.assets.domain.Manufacturers;
import cc.mrbird.assets.service.EquipmentModelService;
import cc.mrbird.assets.service.ManufacturersService;
import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.ResponseBo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(description = "设备型号接口")
@Controller
public class EquipmentModelController extends BaseController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private EquipmentModelService equipmentModelService;
    @Log("获取设备型号")
    @RequestMapping(value = "equip",method = RequestMethod.POST)
    /* @RequiresPermissions("equip:list")*/
    public String index() {
        return "assets/equip/equip";
    }
    @Log("获取设备型号")
    @ApiOperation(value = "获取设备型号" ,  notes="获取设备型号")
    @RequestMapping(value = "equip/list",method = RequestMethod.POST)
    /*@RequiresPermissions("equip:list")*/
    @ResponseBody
    public Map<String, Object> equipmentModelList(QueryRequest request, EquipmentModel equipmentModel) {
        return super.selectByPageNumSize(request, () -> this.equipmentModelService.findAllList(equipmentModel, null));
    }
    @ApiOperation(value = "设备型号添加")
    @RequestMapping(value = "equip/add",method = RequestMethod.POST)
    @ResponseBody
    public ResponseBo add(EquipmentModel equipmentModel) {
        try {
            EquipmentModel result = this.equipmentModelService.findByName(equipmentModel.getEquipment_model_name());
            if (result == null) {
                this.equipmentModelService.add(equipmentModel);
            }
            return ResponseBo.ok();
        } catch (Exception e) {
            log.error("设备型号添加失败", e);
            return ResponseBo.error("设备型号添加失败，请重新添加！");
        }
    }
}
